import { baseUrl, billBaseUrl } from "@/utils/config.js"
import { random_string } from '@/utils/common.js';

const placeholderStyle = 'color:#ccc;font-size:28rpx;font-weight: bold;'
const displayStyle = 'display: flex;align-items: center;justify-content: center;'
const inputStyle = {
  fontSize: '28rpx',
  textAlign: 'right',
  fontWeight: 'bold',
}
const rightStyle = 'width: 44rpx;height: 70rpx;display: flex;justify-content: flex-end;align-items: center;'
const driverModel = {
  title: '驾校培训收款收据',
  type: 'driver',
  rules: {
    customerName: [{
      required: true,
      message: '请填写学员姓名',
      trigger: ['change', 'blur']
    }],
    actualAmount: [{
      required: true,
      message: '请填写应收金额',
      trigger: ['change', 'blur']
    }]
  },
  data: [[
    {
      key: 'copy',
      type: 'copy',
      placeholder: '粘贴信息，自动拆分学员名称、电话',
      style: 'min-height: 140rpx;',
    }
  ],
  [
    {
      key: 'customerName',
      type: 'input',
      inputType: 'text',
      label: '学员名称',
      placeholder: '填写学员名称',
      customStyle: inputStyle,
      placeholderStyle: placeholderStyle,
      required: true,
      height: 70,
      clearable: false,
      borderBottom: true,
      right: {
        style: rightStyle,
        img: billBaseUrl + 'tiaozhuantongxunlu@3x.png',
        label: '',
        imageViewStyle: displayStyle + 'width: 32rpx;height:32rpx;flex-shrink: 0;',
        func: 'chooseMember'
      },
    },
    {
      key: 'customerPhone',
      type: 'input',
      inputType: 'number',
      label: '联系电话',
      placeholder: '请填写学员联系方式',
      customStyle: inputStyle,
      placeholderStyle: placeholderStyle,
      required: false,
      height: 70,
      clearable: false,
      borderBottom: true,
      right: null,
    },
    {
      key: 'otherInfo',
      subKey: 'sex',
      type: 'select',
      label: '性别',
      labels: ['男', '女'],
      func: 'selectType',
      borderBottom: false,
      style: 'justify-content: flex-end;'
    }
  ], [
    {
      key: 'idNumber',
      type: 'input',
      inputType: 'idcard',
      label: '身份证号',
      placeholder: '请填写身份证号',
      customStyle: inputStyle,
      placeholderStyle: placeholderStyle,
      required: false,
      height: 70,
      clearable: false,
      borderBottom: false,
      right: null,
    },
    {
      key: 'otherInfo',
      subKey: 'type',
      type: 'input',
      inputType: 'text',
      label: '报考类型',
      placeholder: '请填写报考类型',
      customStyle: inputStyle,
      placeholderStyle: placeholderStyle,
      required: false,
      height: 70,
      clearable: false,
      borderBottom: true,
      right: null,
    }, {
      key: 'otherInfo',
      subKey: 'feeA',
      type: 'input',
      inputType: 'number',
      label: '代收费',
      placeholder: '请输入代收费费用',
      customStyle: inputStyle,
      placeholderStyle: placeholderStyle,
      required: false,
      height: 70,
      clearable: false,
      borderBottom: true,
      right: null,
    }, {
      key: 'otherInfo',
      subKey: 'feeB',
      type: 'input',
      inputType: 'number',
      label: '培训费',
      placeholder: ' 请输入培训费费用',
      customStyle: inputStyle,
      placeholderStyle: placeholderStyle,
      required: false,
      height: 70,
      clearable: false,
      borderBottom: false,
      right: null,
    }
  ], [
    {
      type: 'money',
      placeholderStyle: 'color:#ccc;font-size:28rpx;font-weight: bold;',
      customStyle: {
        fontSize: '28rpx',
        textAlign: 'right',
        fontWeight: 'bold'
      },
      labels: {
        expenseDetails: '收据明细',
        receivableAmount: '应收金额',
        actualAmount: '实收金额',
        resultAmount: '欠款金额',
        repairTime: '服务时间'
      }
    }
  ], [
    {
      key: 'timeInfo',
      type: 'time',
      label: '服务时间',
      borderBottom: true,
      list: [{
        key: 'day',
        img: baseUrl + 'riqi@3x.png',
        placeholder: '选择服务日期',
        func: 'handleClickDate',
        ref: {
          key: 'timeInfo',
          subKey: 'day',
          type: 'date',
          show: false,
          ref: 'day',
        }
      }, {
        key: 'time',
        img: baseUrl + 'shijian@3x.png',
        placeholder: '选择时间',
        func: 'handleClickTime',
        ref: {
          key: 'timeInfo',
          subKey: 'time',
          type: 'time',
          show: false,
        }
      }]
    },
    {
      key: 'extend',
      subKey: 'payType',
      type: 'select',
      label: '支付方式',
      labels: ['微信', '支付宝', '转账', '现金', '其他'],
      func: 'selectType',
      borderBottom: true,
    },
    {
      key: 'remark',
      type: 'textarea',
      inputType: 'maintain-remark',
      label: '备注信息',
      placeholder: '请填写备注信息',
      style: 'min-height: 240rpx;',
      func: 'editRemark',
      right: {
        label: '选模板',
        func: 'chooseRemark'
      }
    }
  ], [
    {
      key: 'extend',
      subKey: 'customerSignSwitch',
      type: 'switch',
      label: '是否需要客户签字'
    }
  ],
  [
    {
      key: 'extend',
      type: 'seal',
    }
  ]],
  sealInfos: [
    {
      label: "水印",
      selectText: '选择电子水印',
      url: '',
      selected: true,
      value: '1',
      code: 'ELECTRON',
      width: 202
    },
    {
      label: "公章",
      selectText: '选择公章',
      url: '',
      selected: false,
      value: '2',
      code: 'OFFICIAL',
      width: 202
    },
    {
      label: "不使用",
      url: '',
      selected: false,
      value: '3',
      code: '',
      width: 202
    }
  ],
  initFormFunc: (form) => {
    form.actualAmount = 0
    form.remark = '1、本收据是学员接受驾校培训的重要凭证，专人专用，不得转借或涂改，请务必妥善管；\n2、如学员信息变更，请及时与本培训机构相关负责人联系，采集个人信息并完成报名。'
  },
  changeFormFunc: (val) => {
    let form = JSON.parse(JSON.stringify(val))
    form.expenseDetails = [
      { key: 'sex', name: '性别', value: form.otherInfo.sex, uid: random_string() },
      { key: 'type', name: '报考类型', value: form.otherInfo.type, uid: random_string() },
      { key: 'feeA', name: '代收费', value: form.otherInfo.feeA, uid: random_string() },
      { key: 'feeB', name: '培训费', value: form.otherInfo.feeB, uid: random_string() },
    ]
    form.repairTime = form.timeInfo.day + ' ' + form.timeInfo.time
    return form
  },
  setFormFunc: (form) => {
    var keys = ['sex', 'type', 'feeA', 'feeB']
    for (var item of form.expenseDetails) {
      for (var key of keys) {
        if (item.key == key) {
          form.otherInfo[key] = item.value
          break
        }
      }
    }
  }
}

export default driverModel